package com.heima.bos.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.heima.bos.dao.FunctionDaoInter;
import com.heima.bos.domain.Function;
@Repository
public class FunctionDao extends BaseDaoImpl<Function> implements FunctionDaoInter{
	/**
	 * 根据用户id获取对于的权限
	 * @return 
	 */
	public List<Function> findByUserId(String id) {
		String hql = "from Function f left outer join fetch f.roles r left outer join fetch "
				   + "r.users u where u.id=?";
		return this.getHibernateTemplate().find(hql,id);
	}
	/**
	 * 获取所有的菜单(generatemenu=1)
	 */
	public List<Function> findAllMenu() {
		String hql = "From Function where generatemenu='1' order by zindex";
		List<Function> list = this.getHibernateTemplate().find(hql);
		return list;
	}

	public List<Function> findMenuByUserId(String id) {
		String hql = "From Function f left outer join fetch f.roles r "
				   + "left outer join fetch r.users u where generatemenu='1' and u.id=? order by zindex";
		List<Function> list = this.getHibernateTemplate().find(hql,id);
		return list;
	}

}
